﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EC_ASS.Models;


namespace EC_ASS.Controllers
{
    public class DealController : Controller
    {
        //
        // GET: /Deal/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Info(string id, string name)
        {
            DataECDataContext context = new DataECDataContext();
            var deal = (from d in context.Product_Deals
                        join p in context.Products on d.ID equals p.ID
                        where d.ID == id
                        select new DealsModel
                        {
                            DealResult = p,
                            Discount = d.Discount,
                            ExpiredTime = d.ExpiredTime
                        }).Single();
            ViewBag.DealDetail = deal;
            ViewBag.ExpiredTime = deal.ExpiredTime.GetDateTimeFormats()[120];
            // Detail imag
            string[] imgList = deal.DealResult.Detail_Images.Split('_');
            ViewBag.ImgList = imgList;

            // Detail size
            string[] sizeList = deal.DealResult.Size.Split('_');
            ViewBag.Size = sizeList;

            //Load các sản phẩm cùng loại
            var dealList = (from d in context.Product_Deals
                                           join p in context.Products on d.ID equals p.ID
                                           select new DealsModel
                                           {
                                               DealResult = p,
                                               Discount = d.Discount,
                                               ExpiredTime = d.ExpiredTime
                                           }).ToList();
            ViewBag.Name = name;

            return View(dealList);
        }

    }
}
